var http = require("http")
var fs = require("fs")

http.createServer(function(request,response){
  console.log(request.url);
  //console.log(request)
  let call = router[request.url]
  if(call) call(request,response);
  else default_handle(request,response);
}).listen(8888);

router={
'/':hello,
'/monkey.ico':image
}

function hello(request,response){
  response.writeHead(200,{'Content-Type': 'text/html;charset=utf-8'});
  response.end(fs.readFileSync("index.html"));
}

function image(request,response){
  response.writeHead(200,{'Content-Type': 'image/xicon'});
  response.end(fs.readFileSync('monkey.ico'));
}
function default_handle(request,response){
  dir = request.url.slice(1);
  response.writeHead(200,{'Content-Type': 'image/jpg'});
  response.end(fs.readFileSync(dir));
}
console.log('server running at http://127.0.0.1:8888')
